package com.sjx.boundarycallback.utils;

import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class LogUtils {

    private static final String TAG = "LogUtils";

    /**
     * 追加文件：使用FileWriter
     * @param content
     */
    public static void writeLog(String content) {
        String path = Environment.getExternalStorageDirectory() + "Log/"; //文件路径
        FileWriter writer;
        try {
            File file = new File(path);
            if (!file.exists()) {  //没有创建文件夹则创建
                file.mkdir();
                Log.i(TAG, "success");
            }
            // 打开一个写文件器，构造函数中的第二个参数true表示以追加形式写文件
            writer = new FileWriter(path + "log.log", true);
            writer.write(content);
            writer.flush();
            //关闭流
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
